package com.example.example5_2;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;

public class MyAudioService extends Service {

    private static MediaPlayer mp;

    public MyAudioService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return new PlayBinder();
    }

    class PlayBinder extends Binder{
        // 播放音乐
        public void MyMethod(){
            mp = MediaPlayer.create(getApplicationContext(), R.raw.white);
            mp.start();
        }
    }

    // 停止音乐
    @Override
    public void onDestroy() {
        super.onDestroy();
        mp.stop();
    }
}